﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Roster.FlattenedTroopRosterElement
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.Core;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.Roster
{
  public struct FlattenedTroopRosterElement : ISavedStruct
  {
    public static readonly FlattenedTroopRosterElement DefaultFlattenedTroopRosterElement;
    [SaveableField(0)]
    private readonly CharacterObject _troop;
    [SaveableField(1)]
    private readonly int _xp;
    [SaveableField(3)]
    private readonly int _xpGain;
    [SaveableField(4)]
    private readonly UniqueTroopDescriptor _uniqueNo;

    public static void AutoGeneratedStaticCollectObjectsFlattenedTroopRosterElement(
      object o,
      List<object> collectedObjects)
    {
      ((FlattenedTroopRosterElement) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    private void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      collectedObjects.Add((object) this._troop);
      UniqueTroopDescriptor.AutoGeneratedStaticCollectObjectsUniqueTroopDescriptor((object) this._uniqueNo, collectedObjects);
    }

    internal static object AutoGeneratedGetMemberValueState(object o)
    {
      return (object) ((FlattenedTroopRosterElement) o).State;
    }

    internal static object AutoGeneratedGetMemberValue_troop(object o)
    {
      return (object) ((FlattenedTroopRosterElement) o)._troop;
    }

    internal static object AutoGeneratedGetMemberValue_xp(object o)
    {
      return (object) ((FlattenedTroopRosterElement) o)._xp;
    }

    internal static object AutoGeneratedGetMemberValue_xpGain(object o)
    {
      return (object) ((FlattenedTroopRosterElement) o)._xpGain;
    }

    internal static object AutoGeneratedGetMemberValue_uniqueNo(object o)
    {
      return (object) ((FlattenedTroopRosterElement) o)._uniqueNo;
    }

    [SaveableProperty(5)]
    public RosterTroopState State { get; private set; }

    public FlattenedTroopRosterElement(
      CharacterObject troop,
      RosterTroopState state = RosterTroopState.Active,
      int xp = 0,
      UniqueTroopDescriptor uniqueNo = default (UniqueTroopDescriptor),
      int xpGain = 0)
      : this()
    {
      this._troop = troop;
      this._xp = xp;
      this._xpGain = xpGain;
      this.State = state;
      this._uniqueNo = !uniqueNo.IsValid ? new UniqueTroopDescriptor(Game.Current.NextUniqueTroopSeed) : uniqueNo;
    }

    public FlattenedTroopRosterElement(
      FlattenedTroopRosterElement rosterElement,
      RosterTroopState state)
      : this(rosterElement)
    {
      this.State = state;
    }

    private FlattenedTroopRosterElement(FlattenedTroopRosterElement rosterElement)
      : this()
    {
      this._troop = rosterElement._troop;
      this._xp = rosterElement._xp;
      this._xpGain = rosterElement._xpGain;
      this._uniqueNo = rosterElement._uniqueNo;
      this.State = rosterElement.State;
    }

    public CharacterObject Troop => this._troop;

    public bool IsWounded
    {
      get
      {
        if (this.Troop.IsHero)
          return this.Troop.HeroObject.IsWounded;
        return this.State == RosterTroopState.Wounded || this.State == RosterTroopState.WoundedInThisBattle;
      }
      set => this.State = value ? RosterTroopState.Wounded : RosterTroopState.Active;
    }

    public bool IsRouted
    {
      get => this.State == RosterTroopState.Routed;
      set => this.State = value ? RosterTroopState.Routed : RosterTroopState.Active;
    }

    public bool IsKilled
    {
      get => this.State == RosterTroopState.Killed;
      set => this.State = value ? RosterTroopState.Killed : RosterTroopState.Active;
    }

    public int Xp => this._xp;

    public int XpGained => this._xpGain;

    public UniqueTroopDescriptor Descriptor => this._uniqueNo;

    public override string ToString() => this.Troop.ToString();

    bool ISavedStruct.IsDefault()
    {
      return this._troop == null && this._xp == 0 && this._xpGain == 0 && this.State == RosterTroopState.Active && this._uniqueNo == UniqueTroopDescriptor.Invalid;
    }
  }
}
